package com.me.jingdongshop.ui.holder;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.LayoutAnimationController;
import android.view.animation.ScaleAnimation;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.me.common.ui.BaseAdapterLV;
import com.me.common.ui.BaseHolderLV;
import com.me.jingdongshop.R;
import com.me.jingdongshop.model.bean.ListBean;
import com.me.jingdongshop.ui.adapter.GoodsGridViewAdapter;
import com.me.jingdongshop.ui.view.MyGridView;


/**
 * Created by Tm on 2017/5/4.
 */

public class GoodsHolderLv extends BaseHolderLV<ListBean> {
    private TextView tvHeard;
    private MyGridView gridGoods;




    public GoodsHolderLv(Context context, ViewGroup parent, BaseAdapterLV<ListBean> adapter,
                         int position, ListBean bean) {
        super(context, parent, adapter, position, bean);

    }


    @Override
    public View onCreateView(final Context context, ViewGroup parent) {

        final View view = LayoutInflater.from(context).inflate(R.layout.item_category_right, parent, false);

        tvHeard = (TextView) view.findViewById(R.id.tv_heard);
        gridGoods = (MyGridView) view.findViewById(R.id.grid_goods);
        LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.lv_ll);
       // linearLayout.seton
        linearLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (adapter.mListering!=null){
                    adapter.mListering.onclick();
                }
            }
        });


        return view;
    }

    @Override
    protected void onRefreshView(final ListBean bean, int position) {
        //titlet
       /* if (bean.getParentId()==1||bean.getParentId()==11||bean.getParentId()==12||bean.getParentId()==13){
            if (bean.getId()==11){
                tvHeard.setText(adapter.listData.get(position).getName());
            }if ()


        }*/

        tvHeard.setText(bean.getName());

        GoodsGridViewAdapter girdAdapter = new GoodsGridViewAdapter(bean.getDatas(), context);

       gridGoods.setAdapter(girdAdapter);

        gridGoods.setLayoutAnimation(getAnimationController());






    }

    protected LayoutAnimationController getAnimationController(){
        LayoutAnimationController controller;
        ScaleAnimation anim = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);//从0.5倍放大到1倍
        anim.setDuration(500);
        controller=new LayoutAnimationController(anim,0.1f);
        controller.setOrder(LayoutAnimationController.ORDER_NORMAL);
        return controller;
    }







}
